package algorithm_study.leecode;

import java.util.*;

public class GroupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>>res=new ArrayList();
        if(strs.length==0){
            return res;
        }
        Map<String,List<String>> unique=new HashMap();
        for(int i=0;i<strs.length;i++){
            char[]temp= strs[i].toCharArray();
            Arrays.sort(temp);
            String flag=String.valueOf(temp);
            if(unique.containsKey(flag)){
                unique.get(flag).add(strs[i]);
            }else{
                List<String>words=new ArrayList();
                words.add(strs[i]);
                unique.put(flag,words);
                res.add(words);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        String[]strs={"eat","ate","ate"};
        List<List<String>> lists = new GroupAnagrams().groupAnagrams(strs);
        System.out.println(lists);
    }
}
